import java.util.Random;

public class Deliver implements Runnable{

	private NormalMessage msg;
	private ChatFrame cFrame;
	private static int key = 0;
	
	public Deliver(NormalMessage msg, ChatFrame cFrame) {
		this.msg = msg;
		this.cFrame = cFrame;
		new Thread(this, "Delivery").start();
	}
	
	@Override
	public void run() {
		Random rand = new Random();
		int num = rand.nextInt() % 100;
		if (num >= 10) {
			num *= 30;
			try {
				Thread.sleep(num);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			while (key == 1) {}
			key = 1;
			cFrame.addTextToChat(msg);
			key = 0;
		}
		
	}
	
}
